home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 January
/
Macworld (1998-01).dmg
/
Shareware World
/
Comms & Internet
/
HTML mode 2.0 etc.
/
html.tcl
< prev
next >
Wrap
Text File
|
1997-09-22
|
33KB
|
927 lines
## -*-Tcl-*-
# ###################################################################
# HTML mode 2.0: tools for editing HTML documents
#
# FILE: "html.tcl"
# created: 95-04-26 14.49.04
# last update: 97-09-22 20.18.59
# Author: Johan Linde
# E-mail: <jl@theophys.kth.se>
# www: <http://bach.theophys.kth.se/~jl/Alpha.html>
#
# Version: 2.0
#
# version 0.24 (16 July 95) by Scott W. Brim <swb1@cornell.edu>
# version 1.0 -- 2.0 (September 97) by Johan Linde <jl@theophys.kth.se>
#
# Copyright 1996, 1997 by Johan Linde
#
# This software may be used freely, and distributed freely, as long as the
# receiver is not obligated in any way by receiving it.
#
# If you make improvements to this file, please share them!
#
# ###################################################################
##
# ◊◊◊◊ Change below for new system §0 ◊◊◊◊ #
# ◊◊◊◊ end changing for new system §0 ◊◊◊◊ #
# called by Alpha to load HTML in.
proc htmlDummy {} {}
proc htmlMenu {} {}
proc htmlUtilsMenu {} {}
#===============================================================================
# Global variables and their management
#===============================================================================
# ◊◊◊◊ Change below for new system §1 ◊◊◊◊ #
# Line width
newModeVar HTML fillColumn 75 0
newModeVar HTML leftFillColumn 0 0
# word breaking and word wrapping
newModeVar HTML wordBreak {\w+} 0
newModeVar HTML wordBreakPreface {(\W)} 0
newModeVar HTML wrapBreak {[\w_]+} 0
newModeVar HTML wrapBreakPreface {([^\w_])} 0
# Indentation
newModeVar HTML indentHEAD 0 1
newModeVar HTML indentBODY 0 1
newModeVar HTML indentP 0 1
newModeVar HTML indentDIV 0 1
newModeVar HTML indentBLOCKQUOTE 0 1
newModeVar HTML indentCENTER 0 1
newModeVar HTML indentMULTICOL 0 1
newModeVar HTML indentOBJECT 0 1
newModeVar HTML indentNOEMBED 0 1
newModeVar HTML indentOL 1 1
newModeVar HTML indentUL 1 1
newModeVar HTML indentDIR 1 1
newModeVar HTML indentMENU 1 1
newModeVar HTML indentDL 1 1
newModeVar HTML indentFORM 0 1
newModeVar HTML indentSELECT 0 1
newModeVar HTML indentTABLE 1 1
newModeVar HTML indentTR 1 1
# newModeVar HTML indentTD 0 1
newModeVar HTML indentFRAMESET 0 1
newModeVar HTML indentNOFRAMES 0 1
newModeVar HTML indentMAP 0 1
newModeVar HTML indentAPPLET 0 1
newModeVar HTML indentNOSCRIPT 0 1
set htmlIndentElements {HEAD BODY P DIV BLOCKQUOTE CENTER MULTICOL OBJECT NOEMBED OL UL DIR MENU DL
FORM SELECT TABLE TR FRAMESET NOFRAMES MAP APPLET NOSCRIPT}
# browsers
if {![info exists browserSig] && [catch {getFileSig [icGetPref -t 1 Helper•http]} browserSig]} {set browserSig MOSS}
newModeVar HTML browsers {MOSS MSIE} 0
newModeVar HTML wordWrap 1 1
newModeVar HTML prefixString "<!-- " 0
newModeVar HTML suffixString " -->" 0
# Paths to footer files.
newModeVar HTML footers {} 0
# Tag color
newModeVar HTML tagColor blue 0
# Attribute color
newModeVar HTML attributeColor magenta 0
# Simple coloring?
newModeVar HTML simpleColoring 0 1
# Should elements be lower case?
newModeVar HTML useLowerCase 0 1
# Should •'s be inserted?
newModeVar HTML useTabMarks 1 1
# Is <p> a container?
newModeVar HTML pIsContainer 1 1
# Are LI DT and DD containers
newModeVar HTML lidtAreContainers 0 1
# A window cache with frames.
newModeVar HTML windows {} 0
# When browser is launched, should it be brought to front?
newModeVar HTML browseInForeground 1 1
# Save without asking when sending file to browser?
newModeVar HTML saveWithoutAsking 0 1
# list of commonly used character entities
newModeVar HTML defaultCommonChars {"less than" "greater than" "ampersand"} 0
newModeVar HTML commonChars $HTMLmodeVars(defaultCommonChars) 0
# Which HTML package?
newModeVar HTML htmlPackageToUse 1 0
# Hide Netscape or MSIE only tags?
newModeVar HTML hideNetscape 0 1
newModeVar HTML hideIE 1 1
# Include event handlers in attribute dialog?
newModeVar HTML inclEventHandler 0 1
# Include style sheet attributes in attribute dialog?
newModeVar HTML hideStyleAttrs 1 1
# Beep when asking for attributes in the status bar?
newModeVar HTML promptNoisily 1 1
# Input from big windows?
newModeVar HTML useBigWindows 1 1
# Change in big windows?
newModeVar HTML changeInBigWindows 1 1
# Settings in Use Attributes menu apply to dialogs?
newModeVar HTML useAttsApplyToDialogs 0 1
# Cmd-double-click on non text file link opens file?
newModeVar HTML openNonTextFile 1 1
# Return on non text file in home page window opens file?
newModeVar HTML homeOpenNonTextFile 1 1
# Check anchors in links
newModeVar HTML checkAnchors 1 1
# Case sensistive link checking?
newModeVar HTML caseSensitive 0 1
# Check links with Big Brother?
newModeVar HTML useBigBrother 0 1
newModeVar HTML checkInFront 1 1
newModeVar HTML useBBoptions 1 1
newModeVar HTML ignoreRemote 0 1
newModeVar HTML ignoreLocal 0 1
# Folder for HTML manual.
newModeVar HTML manualFolder "$HOME:HTML mode manual" 0
newModeVar HTML manualStartPage 0 0
# FTP servers
newModeVar HTML FTPservers {} 0
# Last modified string
newModeVar HTML lastModified "Last modified" 0
# JavaScript stuff
newModeVar HTML JavaScriptColoring 0 1
newModeVar HTML JavaScriptColor magenta 0
newModeVar HTML stringColor green 0
newModeVar HTML JavaCommentColor red 0
newModeVar HTML elecRBrace 1 1
newModeVar HTML elecLBrace 1 1
newModeVar HTML electricSemi 1 1
# CSS stuff
newModeVar HTML CSSColoring 0 1
newModeVar HTML CSSColor cyan 0
# ◊◊◊◊ end changing for new system §1 ◊◊◊◊ #
# These attributes are URLs.
set htmlURLAttr {HREF= SRC= LOWSRC= ACTION= USEMAP= BACKGROUND= CODEBASE= PLUGINSPAGE=
DYNSRC= CLASSID= DATA=}
# These element attributes are colors
set htmlColorAttr {BGCOLOR= TEXT= LINK= VLINK= ALINK= COLOR= BORDERCOLOR=
BORDERCOLORDARK= BORDERCOLORLIGHT=}
# These attributes are windows
set htmlWindowAttr {TARGET=}
# Special cases with URLs, colors and windows
set htmlSpecURL {}
set htmlSpecColor {}
set htmlSpecWindow {}
# These elements can be in document HEAD.
set htmlHeadElements1 {BASE ISINDEX LINK META STYLE SCRIPT}
set htmlHeadElements3 {BASE ISINDEX LINK META STYLE}
# These elements are plug-ins.
set htmlPlugins {EMBED LIVEAUDIO LIVEVIDEO "QUICKTIME MOVIE" "QUICKTIME VR" REALAUDIO}
# HTML mode version
set htmlVersion 2.0
# Register eventhandler for Big Brother events
eventHandler Bbth Chkd htmlBbthChkdHandler
# Used by fillParagraph
set htmlParaCommands {html|head|title|body|h[1-6]|p|div|blockquote|center|address|pre|multicol}
append htmlParaCommands {|br|hr|wbr|basefont|ul|ol|li|dir|menu|dl|dd|dt|form|input}
append htmlParaCommands {|select|option|textarea|caption|table|tr|frameset|frame|noframes}
append htmlParaCommands {|map|area|applet|param|script|noscript|layer|ilayer|nolayer|base|link|meta|isindex}
append htmlParaCommands {|col|colgroup|marquee|object|thead|tbody|tfoot}
#
# Internal Globals
#
set htmlCurSel ""
set htmlIsSel 0
set htmlAdditionExist 0
set htmlHomePageWinList {}
set homeTime 0
set htmlFTPing 0
set htmlNumBbthChecking 0
# Load other HTML mode files.
foreach tmp {htmlEngine htmlElems htmlUtils hctsmslShared hctsmslMenu htmlMenu} {
if {[info exists cssModeIsLoaded] && ($tmp == "hctsmslMenu" || $tmp == "hctsmslShared")} {continue}
if { [catch {eval ${tmp}.tcl}] } {
beep
alertnote "Loading of ${tmp}.tcl failed"
return
}
}
if {(!$HTMLmodeVars(useBigWindows) || !$HTMLmodeVars(changeInBigWindows)) && [catch {htmlStatusBar.tcl}] } {
beep
alertnote "Loading of htmlStatusBar.tcl failed"
return
}
# Silently add missing menu.
if {[lsearch -exact $modeMenus(HTML) htmlMenu] >= 0 && [lsearch -exact $modeMenus(HTML) htmlUtilsMenu] < 0} {
lappend modeMenus(HTML) htmlUtilsMenu
}
if {[lsearch -exact $modeMenus(HTML) htmlMenu] < 0 && [lsearch -exact $modeMenus(HTML) htmlUtilsMenu] >= 0} {
lappend modeMenus(HTML) htmlMenu
}
# Clean up tmp files
if {[file exists $PREFS:HTMLtmp]} {catch {rm $PREFS:HTMLtmp:*}}
# Clean up after version 2.0b1
if {[info exists htmlMenuKey]} {
foreach tmp [array names htmlMenuKey] {
removeArrDef htmlMenuKey $tmp
}
htmlWriteMenuKeys
}
#
# Read custom elements
#
proc htmlReadAdditions {} {
global PREFS htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
global htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
global htmlSpecURL htmlSpecColor htmlSpecWindow htmlVersion htmlShownWarning
htmlExtensions.tcl
message "Loading custom elements…"
if {[catch {open $PREFS:HTMLadditions.tcl r} fid]} {
alertnote "Could not open the file HTMLAdditions.tcl with your custom elements."
return
}
set additions [read -nonewline $fid]
close $fid
set lines [split $additions "\n"]
set version [lindex $lines 0]
if {$version == $htmlVersion} {htmlReadAdditions0 $lines; return}
if {$version > $htmlVersion} {
regsub "\[^\n\]+" $additions $htmlVersion additions
set fid [open $PREFS:HTMLadditions.tcl w]
puts $fid $additions
close $fid
htmlReadAdditions0 $lines
return
}
set allattrs [htmlGetAllAttrs]
set newLines "$htmlVersion\n"
set changed 0
set tmpSpecURL ""
set tmpSpecColor ""
set tmpSpecWindow ""
foreach line [lrange $lines 1 end] {
set elem [lindex $line 0]
set command [lindex $line 1]
set elemExists [info exists htmlElemAttrOptional1($elem)]
if {$elemExists} {
foreach x [list AttrOptional1 AttrRequired1 AttrNumber1 AttrChoices1 EventHandler1] {
if {[info exists htmlElem${x}($elem)]} {
set $x [string toupper [set htmlElem${x}($elem)]]
} else {
set $x ""
}
}
set attrs [concat $AttrOptional1 $AttrRequired1 $EventHandler1]
foreach at $attrs {
if {[string trimright $at =] == $at} {
lappend attrs "${at}="
} else {
lappend attrs [string trimright $at =]
}
}
} else {
set attrs {}
}
set var [lindex $command 1]
foreach ucw [list URL Color Window] {
if {$var == "html${ucw}Attr"} {
set att [lindex $command 2]
if {[lsearch -exact [set html${ucw}Attr] $att] >=0} {
# Already defined.
set changed 1
} elseif {[lsearch -exact $allattrs $att] >=0 || [lsearch -exact $allattrs [string trimright $att =]] >=0} {
# Used for some other kind of attr.
lappend ${ucw}SpecMaybe $att
set changed 1
} elseif {[lsearch -exact $attrs $att] >= 0} {
# Attr already exists for elem.
lappend ${ucw}Maybe $att
set changed 1
} else {
append newLines "$line\n"
}
}
if {$var == "htmlSpec${ucw}"} {
set tmpadd [lrange $command 2 end]
foreach x $tmpadd {
regexp {[^!=]!?=(.*)} $x dum tmp
# Only add if attr doesn't exist.
if {[lsearch -exact $attrs $tmp] >= 0} {
set changed 1
set where [lsearch -exact $tmpadd $x]
set tmpadd [lreplace $tmpadd $where $where]
}
}
if {[llength $tmpadd]} {
append newLines "[list $elem] \{lappend htmlSpec${ucw} $tmpadd\}\n"
append tmpSpec${ucw} " " $tmpadd
}
}
}
if {[lsearch {htmlURLAttr htmlColorAttr htmlWindowAttr htmlSpecURL \
htmlSpecColor htmlSpecWindow} $var] < 0} {
# If element doesn't exist, GO!
if {!$elemExists} {
append newLines "$line\n"
regsub "html" $command "tmp" command
eval $command
continue
}
# Skip these vars if element exists.
if {[string match "htmlElemKeyBinding*" $var] || [string match "htmlElemProc*" $var] ||
$var == "htmlPlugins"} {
set changed 1
continue
}
regexp {([^\(]+)\(([^\)]+)\)[ ]+(.+)} [lrange $command 1 end] dummy var arg added
set added [string trimleft [string trimright $added \}] \{]
foreach c $added {
if {$var == "htmlElemAttrChoices1"} {
regexp {[^=]*=} $c tmp
# Don't add choices if they exist or if attr isn't a choice attr.
if {[lsearch -exact $AttrChoices1 $c] >= 0 || ([lsearch -exact $attrs $tmp] >= 0 &&
[lsearch $AttrChoices1 "${tmp}*"] < 0) } {
set changed 1
set where [lsearch -exact $added $c]
set added [lreplace $added $where $where]
}
} else {
if {$var == "htmlElemAttrNumber1"} {
regexp {[^=]*=} $c tmp
} else {
set tmp [string toupper $c]
}
# Don't add attrs which exist.
if {[lsearch -exact $attrs $tmp] >= 0} {
set changed 1
set where [lsearch -exact $added $c]
set added [lreplace $added $where $where]
}
}
}
if {[llength $added]} {
append newLines "[list $elem] \{lappend ${var}($arg) $added\}\n"
regsub "html" $var "tmp" var
eval "lappend ${var}($arg) $added"
}
}
}
foreach ucw [list URL Color Window] {
if {[info exists ${ucw}SpecMaybe]} {
foreach m [set ${ucw}SpecMaybe] {
foreach e [array names tmpElemAttrRequired1] {
if {[lsearch -exact $tmpElemAttrRequired1($e) $m] >= 0 && \
[lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
append newLines "[list $e] \{lappend htmlSpec${ucw} ${e}=[string trimright $m =]\}\n"
}
}
foreach e [array names tmpElemAttrOptional1] {
if {[lsearch -exact $tmpElemAttrOptional1($e) $m] >= 0 && \
[lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
append newLines "[list $e] \{lappend htmlSpec${ucw} ${e}=[string trimright $m =]\}\n"
}
}
}
}
if {[info exists ${ucw}Maybe]} {
foreach m [set ${ucw}Maybe] {
set foundit 0
foreach e [array names tmpElemAttrRequired1] {
if {[lsearch -exact $tmpElemAttrRequired1($e) $m] >= 0 && \
[lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
append newLines "[list $e] \{lappend html${ucw}Attr $m\}\n"
set foundit 1
break
}
}
if {$foundit} {continue}
foreach e [array names tmpElemAttrOptional1] {
if {[lsearch -exact $tmpElemAttrOptional1($e) $m] >= 0 && \
[lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
append newLines "[list $e] \{lappend html${ucw}Attr $m\}\n"
break
}
}
}
}
}
if {$newLines != "$htmlVersion\n"} {htmlReadAdditions0 [split [string trimright $newLines "\n"] "\n"]}
if {$changed} {
beep
if {[lindex [dialog -w 300 -h 270 -b "Clean up" 20 240 100 260 \
-b "Leave it" 120 240 200 260 -t "Some of your custom elements are supported by this\
version of HTML mode." 10 10 290 45 -t "Choose 'Clean up' to update your file with custom\
elements and to avoid this alert next time you run Alpha.\
If you do so, some elements will not be defined correctly if you go back to\
a previous version of HTML mode." 10 50 290 150 -t "Choose 'Leave it' to leave your file\
with custom elements untouched. If you do so, the submenu 'Extend', where you can add new custom\
elements, will be disabled." 10 160 290 225] 1]} {
set htmlShownWarning 1
return
}
}
if {$newLines == "$htmlVersion\n"} {
removeFile $PREFS:HTMLadditions.tcl
} else {
set fid [open $PREFS:HTMLadditions.tcl w]
puts -nonewline $fid $newLines
close $fid
}
}
proc htmlReadAdditions0 {lines} {
global htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
global htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
global htmlSpecURL htmlSpecColor htmlSpecWindow htmlAdditionExist htmlShownWarning
foreach line [lrange $lines 1 end] {
if {[catch {eval [lindex $line 1]}]} {
alertnote "There is an error in the file HTMLAdditions.tcl with your custom elements."
set htmlShownWarning 1
break
}
}
set htmlAdditionExist 1
}
#
# Color support
#
proc htmlColorizing {{changing 0}} {
global HTMLmodeVars HTMLwords htmlElemAttrOptional1 htmlElemAttrRequired1
global htmlElemEventHandler1 PREFS htmlElemKeyBinding
set HTMLKeyWords {}
if {[info exists HTMLwords]} {set HTMLKeyWords $HTMLwords}
if {!$HTMLmodeVars(simpleColoring)} {
# All HTML elements
set allHTMLwords [concat {A ADDRESS APPLET AREA B BASE BASEFONT
BGSOUND BIG BLINK BLOCKQUOTE BODY BR
CAPTION CENTER CITE CODE COL COLGROUP DD DFN DIR DIV DL DT EM EMBED FONT
FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME ILAYER IMG
INPUT ISINDEX KBD KEYGEN LAYER LI LINK MAP MARQUEE MENU META MULTICOL NOBR
NOEMBED NOFRAMES NOLAYER NOSCRIPT OBJECT OL OPTION P PARAM PRE SAMP SCRIPT
SELECT SMALL SPACER SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD
TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR WBR} [array names htmlElemKeyBinding]]
foreach elem $allHTMLwords {
lappend allHTMLkeywords "<${elem}" "/${elem}"
}
# All attributes
set attributeWords {ABOVE= ACTION= ALIGN= ALINK= ALT= ARCHIVE=
AUTOPLAY= AUTOSTART= BACKGROUND=
BEHAVIOR= BELOW= BGCOLOR= BGPROPERTIES= BORDER= BORDERCOLOR=
BORDERCOLORDARK= BORDERCOLORLIGHT= CELLPADDING= CELLSPACING= CHALLENGE=
CHECKED CLASS= CLASSID= CLEAR= CLIP= CODE= CODEBASE= CODETYPE= COLOR= COLS=
COLSPAN= COMPACT CONSOLE= CONTENT= CONTROLLER= CONTROLS CONTROLS= COORDS=
CORRECTION= DATA= DECLARE DIRECTION= DYNSRC= ENCTYPE= FACE= FOV= FRAME=
FRAMEBORDER= FRAMESPACING= GUTTER= HEIGHT= HIDDEN= HREF= HSPACE=
HTTP-EQUIV= ID= ISMAP LANGUAGE= LEFT= LEFTMARGIN= LINK= LOOP= LOWSRC=
MARGINHEIGHT= MARGINWIDTH= MAXLENGTH= MAYSCRIPT METHOD= MULTIPLE NAME=
NODE= NOHREF NOLABELS= NORESIZE NOSHADE NOWRAP PAGEX= PAGEY= PAN=
PLAYEVERYFRAME= PLUGINSPAGE= POINT-SIZE= PROMPT= REL= REV= ROWS= ROWSPAN=
RULES= SCROLLAMOUNT= SCROLLDELAY= SCROLLING= SELECTED SHAPE= SHAPES SIZE=
SPAN= SRC= STANDBY= START= STYLE= TARGET= TEXT= TILT= TITLE= TOP=
TOPMARGIN= TYPE= USEMAP= VALIGN= VALUE= VALUETYPE= VISIBILITY= VLINK=
VSPACE= WIDTH= WRAP= Z-INDEX=}
# Custom element attributes
if {[file exists $PREFS:HTMLadditions.tcl] && ![catch {open $PREFS:HTMLadditions.tcl} fid]} {
set lines [lrange [split [read -nonewline $fid] "\n"] 1 end]
close $fid
foreach line $lines {
set cmd [lindex $line 1]
set added ""
regexp {([^\(]+)\(([^\)]+)\)[ ]+(.+)} [lrange $cmd 1 end] dummy var arg added
set added [string trimleft [string trimright $added \}] \{]
if {$var == "htmlElemAttrRequired1" || $var == "htmlElemAttrOptional1"} {
foreach attr $added {
if {[lsearch -exact $attributeWords $attr] < 0} {
lappend attributeWords $attr
}
}
}
}
}
# A few other words.
lappend allHTMLkeywords "<!--" "-->" "#INCLUDE" "/#INCLUDE" \
"#LASTMODIFIED" "/#LASTMODIFIED" "#DOCINDEX" "/#DOCINDEX"
lappend attributeWords "FILE=" "FORM="
# JavaScript keywords.
set JavaScriptWords {break case continue default do for in function if else new return switch this var while with true false }
foreach elem [array names htmlElemEventHandler1] {
foreach event $htmlElemEventHandler1($elem) {
if {[lsearch -exact $JavaScriptWords $event] < 0} {
lappend JavaScriptWords $event
}
}
}
# CSS keywords
set CSSwords {font-family font-style font-variant font-weight font-size font
color background-color background-image background-repeat background-attachment
background-position background word-spacing letter-spacing text-decoration
vertical-align text-transform text-align text-indent line-height
margin-top margin-right margin-bottom margin-left margin padding-top padding-right
padding-bottom padding-left padding border-top-width border-right-width
border-bottom-width border-left-width border-width border-color border-style
border-top border-right border-bottom border-left border width height float clear
display white-space list-style-type list-style-image list-style-position list-style
@import important}
if {!$changing} {
regModeKeywords -i "<" -i ">" -I $HTMLmodeVars(tagColor) \
-s $HTMLmodeVars(stringColor) -b "/*" "*/" -e "//" HTML {}
}
if {$HTMLmodeVars(JavaScriptColoring) || $HTMLmodeVars(CSSColoring)} {
set col $HTMLmodeVars(JavaCommentColor)
} else {
set col none
}
regModeKeywords -a -c $col HTML
if {$HTMLmodeVars(JavaScriptColoring)} {
set col $HTMLmodeVars(JavaScriptColor)
} else {
set col none
}
regModeKeywords -a -k $col HTML $JavaScriptWords
if {$HTMLmodeVars(CSSColoring)} {
set col $HTMLmodeVars(CSSColor)
} else {
set col none
}
regModeKeywords -a -k $col HTML $CSSwords
regModeKeywords -a -k $HTMLmodeVars(tagColor) \
HTML [concat $HTMLKeyWords $allHTMLkeywords]
regModeKeywords -a -k $HTMLmodeVars(attributeColor) HTML $attributeWords
} else {
regModeKeywords -b "<" ">" -c $HTMLmodeVars(tagColor) \
-k $HTMLmodeVars(tagColor) HTML $HTMLKeyWords
}
}
# Change color when a color variable is changed.
proc htmlChangeColorizing {flag} {
global HTMLmodeVars
set msg 0
switch -glob $flag {
simpleColoring {
htmlColorizing
set msg 1
}
JavaScriptColoring -
attributeColor -
CSSColoring {
if {!$HTMLmodeVars(simpleColoring)} {
htmlColorizing 1
}
}
tagColor {
if {$HTMLmodeVars(simpleColoring)} {
regModeKeywords -a -c $HTMLmodeVars(tagColor) HTML
} else {
regModeKeywords -a -i "<" -i ">" -I $HTMLmodeVars(tagColor) HTML
htmlColorizing 1
}
}
JavaScriptColor {
if {$HTMLmodeVars(JavaScriptColoring) && !$HTMLmodeVars(simpleColoring)} {
htmlColorizing 1
}
}
JavaCommentColor {
if {($HTMLmodeVars(JavaScriptColoring) || $HTMLmodeVars(CSSColoring)) && !$HTMLmodeVars(simpleColoring)} {
regModeKeywords -a -c $HTMLmodeVars(JavaCommentColor) HTML
}
}
CSSColor {
if {$HTMLmodeVars(CSSColoring) && !$HTMLmodeVars(simpleColoring)} {
htmlColorizing 1
}
}
stringColor {
if {!$HTMLmodeVars(simpleColoring)} {
regModeKeywords -a -s $HTMLmodeVars(stringColor) HTML
}
}
}
htmlRedraw
if {$msg} {message "Coloring may not change until you switch to another window."}
}
proc htmlShadowAttrUse {args} {
global HTMLmodeVars htmlMenu
enableMenuItem $htmlMenu "Use Attributes…" [htmlUseAttrsIsEnabled]
}
trace variable HTMLmodeVars(useBigWindows) w htmlShadowAttrUse
trace variable HTMLmodeVars(changeInBigWindows) w htmlShadowAttrUse
trace variable HTMLmodeVars(useAttsApplyToDialogs) w htmlShadowAttrUse
trace variable browserSig w htmlToggleBrowser2
# Dialog to set HTML mode variables.
proc HTMLmodifyFlags {{which General}} {
global HTMLmodeVars modifiedModeVars
set box [eval html${which}PrefsBox]
set allFlags [eval html${which}Flags]
set attrTxt {"status bar" "dialog boxes"}
set manTxt {"first page in manual" "table of contents without frames" "table of contents with frames"}
set values [eval [concat dialog -w 460 -h 315 -b OK 20 285 85 305 -b Cancel 110 285 175 305 $box]]
if {[lindex $values 1]} {return}
set i 1
if {$which == "General"} {incr i}
foreach flag $allFlags {
global $flag
incr i
set val [lindex $values $i]
if {$flag == "useBigWindows" || $flag == "changeInBigWindows"} {set val [lsearch -exact $attrTxt $val]}
if {$flag == "manualStartPage"} {set val [lsearch -exact $manTxt $val]}
if {$HTMLmodeVars($flag) != $val} {
set $flag $val
set HTMLmodeVars($flag) $val
lappend modifiedModeVars [list $flag HTMLmodeVars]
if {[string match "*Color*" $flag]} {htmlChangeColorizing $flag}
}
}
}
proc htmlGeneralPrefsBox {} {
global HTMLmodeVars colorInds
set colors {none blue cyan green magenta red white yellow}
foreach c [lsort [array names colorInds]] {
if {[regexp {color} $c]} {lappend colors $c}
}
set attrTxt {"status bar" "dialog boxes"}
set manTxt {"first page in manual" "table of contents without frames" "table of contents with frames"}
set box "-t {General HTML mode Preferences} 100 10 450 30 \
-m {{Page 1 of preferences} {Page 1 of preferences} {Page 2 of preferences}} 100 35 300 55 \
-n {Page 1 of preferences} \
-c {Bring browser to front when sending a window to it} $HTMLmodeVars(browseInForeground) 10 65 450 80\
-c {Save window without asking when sending it to the browser} $HTMLmodeVars(saveWithoutAsking) 10 85 450 100 \
-c {Set tags in lower case} $HTMLmodeVars(useLowerCase) 10 105 200 120 \
-c {Use tab marks (•)} $HTMLmodeVars(useTabMarks) 10 125 450 140 \
-c {<P> has a closing tag </P>} $HTMLmodeVars(pIsContainer) 10 145 450 160 \
-c {<LI>, <DT> and <DD> have closing tags} $HTMLmodeVars(lidtAreContainers) 10 165 450 180 \
-t {Give attributes in} 10 185 150 200\
-m {[list [lindex $attrTxt $HTMLmodeVars(useBigWindows)]] {dialog boxes} {status bar}} 155 185 450 205 \
-t {Change attributes in} 10 210 150 225 \
-m {[list [lindex $attrTxt $HTMLmodeVars(changeInBigWindows)]] {dialog boxes} {status bar}} 155 210 450 230 \
-c {Beep for each attribute (applies only if you use the status bar)} $HTMLmodeVars(promptNoisily) 10 235 450 250 \
-c {Settings in 'Use Attributes…' also apply to attribute dialogs} $HTMLmodeVars(useAttsApplyToDialogs) 10 255 450 270 \
-n {Page 2 of preferences} \
-c {Simple coloring} $HTMLmodeVars(simpleColoring) 10 65 450 80 \
-t {Color of HTML tags:} 10 85 150 100 \
-m [list [concat $HTMLmodeVars(tagColor) $colors]] 160 85 310 105 \
-t {Color of attributes:} 10 110 150 125 \
-m [list [concat $HTMLmodeVars(attributeColor) $colors]] 160 110 310 130 \
-t {Color of strings:} 10 135 150 150 \
-m [list [concat $HTMLmodeVars(stringColor) $colors]] 160 135 310 155 \
-t {'Help' opens} 10 160 95 175 \
-m {[concat [list [lindex $manTxt $HTMLmodeVars(manualStartPage)]] $manTxt]} 100 160 450 180 \
-c {Cmd-double-clicking on non-text file link opens file} $HTMLmodeVars(openNonTextFile) 10 190 450 205 \
-c {Return on non-text file in home page window opens file} $HTMLmodeVars(homeOpenNonTextFile) 10 210 450 225 \
-t {'Last modified' text} 10 235 150 255 -e [list $HTMLmodeVars(lastModified)] 160 235 450 250"
return $box
}
proc htmlGeneralFlags {} {
return [list browseInForeground saveWithoutAsking useLowerCase useTabMarks pIsContainer lidtAreContainers \
useBigWindows changeInBigWindows promptNoisily useAttsApplyToDialogs simpleColoring \
tagColor attributeColor stringColor manualStartPage openNonTextFile homeOpenNonTextFile lastModified]
}
proc htmlIndentationPrefsBox {} {
global HTMLmodeVars htmlIndentElements
set box "-t {HTML mode Indentation Preferences} 100 10 450 30 \
-t {Indent the content of} 10 40 450 55"
set ww 70; set hh 10
foreach ind $htmlIndentElements {
append box " -c $ind $HTMLmodeVars(indent${ind}) $hh $ww [expr $hh + 100] [expr $ww + 15]"
incr ww 20
if {$ww > 200} {
set ww 70
incr hh 110
}
}
return $box
}
proc htmlIndentationFlags {} {
global htmlIndentElements
foreach ind $htmlIndentElements {
lappend allFlags indent$ind
}
return $allFlags
}
proc htmlJavaScriptPrefsBox {} {
global HTMLmodeVars colorInds
set colors {none blue cyan green magenta red white yellow}
foreach c [lsort [array names colorInds]] {
if {[regexp {color} $c]} {lappend colors $c}
}
set box "-t {HTML mode JavaScript and CSS Preferences} 100 10 450 30 \
-c {Electric left braces} $HTMLmodeVars(elecLBrace) 10 35 450 50 \
-c {Electric right braces} $HTMLmodeVars(elecRBrace) 10 55 450 70 \
-c {Electric semicolon} $HTMLmodeVars(electricSemi) 10 75 450 90 \
-c {Color JavaScript keywords} $HTMLmodeVars(JavaScriptColoring) 10 95 450 110\
-c {Include event handlers in attribute dialog} $HTMLmodeVars(inclEventHandler) 10 115 450 130 \
-t {Color of JavaScript keywords:} 10 135 215 150 \
-m [list [concat $HTMLmodeVars(JavaScriptColor) $colors]] 220 135 360 155 \
-c {Color CSS keywords} $HTMLmodeVars(CSSColoring) 10 165 450 180\
-t {Color of CSS keywords:} 10 185 215 200 \
-m [list [concat $HTMLmodeVars(CSSColor) $colors]] 220 185 360 205 \
-t {Color of JavaScript and CSS comments:} 10 210 270 225 \
-m [list [concat $HTMLmodeVars(JavaCommentColor) $colors]] 275 210 420 230"
return $box
}
proc htmlJavaScriptFlags {} {
return [list elecLBrace elecRBrace electricSemi\
JavaScriptColoring inclEventHandler JavaScriptColor CSSColoring CSSColor JavaCommentColor]
}
proc htmlCheckingPrefsBox {} {
global HTMLmodeVars
set box "-t {HTML mode Checking Links Preferences} 100 10 450 30 \
-t {These settings apply when you check links with Alpha:} 10 40 450 55 \
-c {Check anchors} $HTMLmodeVars(checkAnchors) 10 60 450 75 \
-c {Case sensitive checking (slower)} $HTMLmodeVars(caseSensitive) 10 80 450 95 \
-t {These settings apply when you check links with Big Brother:} 10 105 450 120\
-c {Bring Big Brother to front when checking links} $HTMLmodeVars(checkInFront) 10 125 450 140\
-c {Use Big Brother's link check options} $HTMLmodeVars(useBBoptions) 10 145 450 160\
-c {Ignore remote links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreRemote) 30 165 450 180\
-c {Ignore local links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreLocal) 30 185 450 200"
return $box
}
proc htmlCheckingFlags {} {
return [list checkAnchors caseSensitive checkInFront useBBoptions ignoreRemote ignoreLocal]
}
proc htmlWordPrefsBox {} {
global HTMLmodeVars
set box "-t {HTML mode Word Wrapping Preferences} 100 10 450 30 \
-t {Line width:} 10 40 90 55 -e [list $HTMLmodeVars(fillColumn)] 100 40 140 55 \
-t characters 145 40 300 55 \
-t {The variables below determine which characters build up words, and the word wrapping. Normally\
there is no need to change them. Read about them in general manual if you want to change them.} \
10 70 450 130 \
-t wordBreak: 10 140 150 155 -e [list $HTMLmodeVars(wordBreak)] 155 140 450 155 \
-t wordBreakPreface: 10 165 150 180 -e [list $HTMLmodeVars(wordBreakPreface)] 155 165 450 180 \
-t wrapBreak: 10 190 150 205 -e [list $HTMLmodeVars(wrapBreak)] 155 190 450 205 \
-t wrapBreakPreface: 10 215 150 230 -e [list $HTMLmodeVars(wrapBreakPreface)] 155 215 450 230"
}
proc htmlWordFlags {} {
return [list fillColumn wordBreak wordBreakPreface wrapBreak wrapBreakPreface]
}
if {[file exists $PREFS:HTMLadditions.tcl]} {
if {[catch {htmlReadAdditions}]} {alertnote "An error occured while reading your custom elements."}
}
rename htmlReadAdditions ""
rename htmlReadAdditions0 ""
htmlBuildMenu
htmlBuildUtilsMenu
htmlColorizing
# Check that all home page folders exist.
set tmp_notfind ""
foreach tmp_hp $HTMLmodeVars(homePages) {
if {![file exists [lindex $tmp_hp 0]] || ![file isdirectory [lindex $tmp_hp 0]]} {
alertnote "Can't find the folder for the home page [lindex $tmp_hp 1][lindex $tmp_hp 2]"
set tmp_notfind "[lindex $tmp_hp 1][lindex $tmp_hp 2]"
}
}
if {$tmp_notfind != ""} {htmlHomePages $tmp_notfind}
catch {unset tmp tmp_notfind tmp_hp}
# Define a couple of key bindings.
bind ',' <zso> {htmlInsertCharacter "less than"} HTML
bind '.' <zso> {htmlInsertCharacter "greater than"} HTML
bind '7' <zso> {htmlInsertCharacter ampersand} HTML
bind 0x31 <zso> {htmlInsertCharacter "nonbreak space"} HTML
bind '\{' <s> htmlLeftBrace HTML
bind '\}' <s> htmlRightBrace HTML
# Comment line
bind 'l' <C> htmlCommentLine HTML
# ◊◊◊◊ Change below for new system §2 ◊◊◊◊ #
if {[info commands useUniversalCompletions] == ""} {
# No Vince's Additions
bind '\r' HTMLcarriageReturn HTML
bind '\;' HTMLelectricSemi HTML
# Option-click in titlebar
# Rename old procs if they exist.
if {![info exists htmlModeIsLoaded] && [info commands getIncludeFiles] != "" && [info commands htmlGetIncludeFiles] == ""} {rename getIncludeFiles htmlGetIncludeFiles}
if {![info exists htmlModeIsLoaded] && [info commands editIncludeFile] != "" && [info commands htmleditIncludeFile] == ""} {rename editIncludeFile htmleditIncludeFile}
# Called when option-clicking on titlebar.
proc getIncludeFiles {} {
global mode
if {$mode != "HTML"} {return [htmlGetIncludeFiles]}
return [htmlGetAttributes]
}
# Called when selecting from the menu in the titlebar.
proc editIncludeFile {arg} {
global mode
if {$mode != "HTML"} {return [htmleditIncludeFile $arg]}
htmlInsertAttributes $arg
}
proc htmlLeftBrace {} {
global HTMLmodeVars
set old $HTMLmodeVars(elecLBrace)
if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
set HTMLmodeVars(elecLBrace) 0
}
catch {electricLeft}
set HTMLmodeVars(elecLBrace) $old
}
proc htmlRightBrace {} {
global HTMLmodeVars
set old $HTMLmodeVars(elecRBrace)
if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
set HTMLmodeVars(elecRBrace) 0
}
catch {electricRight}
set HTMLmodeVars(elecRBrace) $old
}
} else {
# Vince's Additions
proc HTMLOptionTitlebar {} {
global htmlPopUptag
return [set htmlPopUptag [htmlGetAttributes]]
}
proc HTMLOptionTitlebarSelect {item} {
global htmlPopUptag
if {[lsearch -exact $htmlPopUptag $item] >= 0} {
htmlInsertAttributes $item
} else {
error "Not an attribute."
}
}
proc htmlLeftBrace {} {
global elecLBrace
set old $elecLBrace
if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
set elecLBrace 0
}
catch {univ::LeftBrace}
set elecLBrace $old
}
proc htmlRightBrace {} {
global elecRBrace
set old $elecRBrace
if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
set elecRBrace 0
}
catch {univ::RightBrace}
set elecRBrace $old
}
}
# ◊◊◊◊ end changing for new system §2 ◊◊◊◊ #
if {[info exists cssModeIsLoaded] && $htmlVersion != $cssVersion} {
alertnote "Warning: The versions of HTML mode and CSS mode may not be compatible.\
Always install new versions of HTML mode and CSS mode simultaneously."
}
set htmlModeIsLoaded 1
message "HTML initialization complete."